package com.chcit.share.security.token;

import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * Description token身份认证
 *
 * @author liuyang
 * @createDate 2019/4/4
 **/
public class JwtAuthenticationProvider extends DaoAuthenticationProvider {

    public JwtAuthenticationProvider(UserDetailsService userDetailsService, PasswordEncoder passwordEncoder) {
        setUserDetailsService(userDetailsService);
        setPasswordEncoder(passwordEncoder);
    }


    @Override
    public Authentication authenticate(Authentication authentication) throws AuthenticationException {

        //TODO:可以在此处覆写整个登录认证逻辑, 后期将业务逻辑分离出去，让业务系统实现
        return super.authenticate(authentication);

    }

    @Override
    protected void additionalAuthenticationChecks(UserDetails userDetails, UsernamePasswordAuthenticationToken authentication)
            throws AuthenticationException {
        // TODO:可以在此处覆写密码验证逻辑，后期将业务逻辑分离出去，让业务系统实现
        super.additionalAuthenticationChecks(userDetails, authentication);
    }

}